package com.itheima.sc.web.order;

import cn.hutool.core.convert.Convert;
import com.itheima.sc.pojo.order.OmsOrderReturnReason;
import com.itheima.sc.result.Result;
import com.itheima.sc.service.order.OmsOrderReturnReasonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Map;

@RestController
@RequestMapping("returnReason")
public class OmsOrderReturnReasonController {
    @Autowired
    OmsOrderReturnReasonService omsOrderReturnReasonService;
    @GetMapping("list")
    public Result list(
            @RequestParam Map map
    ){
        Integer pageNum = Convert.toInt( map.get("pageNum"));
        Integer pageSize = Convert.toInt( map.get("pageSize"));

        return omsOrderReturnReasonService.listOmsOrder(pageNum,pageSize);
    }

    @PostMapping("create")
    public Result create(@RequestBody Map<String,String> map){
        omsOrderReturnReasonService.create(map);
        return Result.success("添加成功");
    }

    @PostMapping("delete")
    public Result deletReason(@RequestParam Map<String,String> map){
        String ids = map.get("ids");
        String[] split = ids.split(",");
        ArrayList<Long> idss = new ArrayList<>();
        for (String s : split) {
            idss.add(Convert.toLong(s));
        }
        omsOrderReturnReasonService.deletByIds(idss);
        return Result.success("删除成功");
    }
    //修改启动状态
    @PostMapping("update/status")
    public Result updateStatus(@RequestParam Map<String,String> map){
        String ids = map.get("ids");
        String[] split = ids.split(",");
        ArrayList<Long> idss = new ArrayList<>();
        for (String s : split) {
            idss.add(Convert.toLong(s));
        }
        omsOrderReturnReasonService.updateStatus(idss,map);
        return Result.success("修改成功");
    }
    //修改退后原因
    @PostMapping("update/{id}")
    public Result updateById(@PathVariable Long id, @RequestBody OmsOrderReturnReason omsOrderReturnReason){
        omsOrderReturnReasonService.updateReason(id,omsOrderReturnReason);
        return Result.success("修改成功");
    }

    //获取详情
    @GetMapping("{id}")
    public Result getReasonyId(@PathVariable Long id){
        return omsOrderReturnReasonService.getById(id);
    }

}
